const express = require("express");
const { db } = require("../database");

// const { validate, validators } = require("../validate");
// // jwt
// const { getPayloadByToken } = require("../jwt");
// const { makePassword } = require("../utils");

// 创建路由对象，使得用户登录状态检查的中间件只作用于部分路由。
const router = express.Router();
// 导入用户登录状态检查的中间件
const { useAuthorization } = require("./base");
router.use(useAuthorization);

router.get("/name", async (req, res) => {
  const { name } = req.query;
  //   console.log(req.query, name);
  const query = await db.select`select * from person where name = ${name}`;
  //   console.log(query);
    res.send({
      code: 200,
      message: "查取成功",
      result: query,
    });

});

// 将路由作为中间件挂接在 / 根路由上。
const registerRouter = (app) => app.use("/person", router);

module.exports = { registerRouter };
